<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="__PUBLIC__/Components/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="__PUBLIC__/Js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Components/ztree/js/jquery.ztree.core-3.4.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Components/ztree/js/jquery.ztree.excheck-3.4.js"></script>

    <SCRIPT type="text/javascript">
        var setting = {
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "ps", "N": "ps" },
                nocheck : false,
                autoCheckTrigger: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onCheck: function(event, treeId, treeNode){
                    if (treeNode.checkedEx) return;
                    var zTree = $.fn.zTree.getZTreeObj(treeId);
                    treeNode.halfCheck = false;
                    zTree.updateNode(treeNode);
                    treeNode.checkedEx = true;
                }
            }
        };

        $(document).ready(function(){
            var role_id=$("#role_id").val();
            $.post(
                    "__URL__/queryAccess",
                    {"role_id":role_id},
                    function(data){
                        if(data.status==0){
                            alert(data.info);
                        }else{
                            $.fn.zTree.init($("#accessTree"), setting, data.data);
                        }
                    },
                    "json"
            );

            $("#insertAccessBtn").click(function(){
                var nodes=$.fn.zTree.getZTreeObj("accessTree").getCheckedNodes(true);
                $.post(
                        "__URL__/insertAccess",
                        {
                            "role_id":role_id,
                            "data":nodes
                        },
                        function(data){
                            alert(data.info);
                            if(data.status==1){
                                window.location.href=data.data;
                            }
                        },
                        "json"
                );
            });

        });
    </SCRIPT>
</HEAD>

<BODY>
<div>
    <input type="button" value="确认分配权限" id="insertAccessBtn">
</div>
<form action="__URL__/insert" method="post">
    <input type="hidden" value="{$role_id}" name="role_id" id="role_id">
    <div style="background-color: #9db2c6;" >
        <div align="center">
            <ul id="accessTree" class="ztree"></ul>
        </div>
    </div>
</form>
</BODY>
</HTML>